import { prisma } from '@/lib/prisma/client'
import { NextResponse } from 'next/server'

export async function GET() {
  try {
    const tags = await prisma.sceneTag.findMany({
      orderBy: {
        createdAt: 'desc'
      }
    })
    return NextResponse.json(tags)
  } catch (error) {
    console.error('获取标签列表失败:', error)
    return NextResponse.json(
      { error: '获取标签列表失败' },
      { status: 500 }
    )
  }
}

export async function POST(request: Request) {
  try {
    const data = await request.json()
    const tag = await prisma.sceneTag.create({
      data: {
        name: data.name,
        color: data.color,
        userId: 'user_id' // 这里需要从 session 获取用户 ID
      }
    })
    return NextResponse.json(tag)
  } catch (error) {
    console.error('创建标签失败:', error)
    return NextResponse.json(
      { error: '创建标签失败' },
      { status: 500 }
    )
  }
} 